package io.kimmking.javacourse.mq.activemq;

import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.memory.MemoryPersistenceAdapter;

public class ActiveMQServer {

    public static void main(String[] args){
        // 尝试用java代码启动一个ActiveMQ broker server
        // 然后用前面的测试demo代码，连接这个嵌入式的server
    	BrokerService bs = new BrokerService();
    	bs.setUseJmx(true);
    	bs.setBrokerName("JavaBroker");
    	bs.setPersistent(false);
//    	bs.addConnector("tcp://192.168.248.129:61617");
    	try {
			bs.addConnector("tcp://localhost:61617");
//			bs.setUseShutdownHook(false);
	    	bs.setPersistenceAdapter(new MemoryPersistenceAdapter());
	    	bs.start();
	    	System.out.println("JavaBroker started.");
	    	System.in.read();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                try {
                    bs.stop();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.exit(0);
            }
        });
    }
}
